//
//  TIiPhoneNotificationCenter.mm
//  iPhoneAPI
//
//  Created by Philippe H. Regenass on 10.08.07.
//  Copyright 2007 TREEINSPIRED. All rights reserved.
//

#import "TIiPhoneNotificationCenter.h"
#include "PhoneInteraction/UtilityFunctions.h"
#include "PhoneInteraction/PhoneInteraction.h"

enum
{
	MENU_ITEM_GENERATE = 10,
	MENU_ITEM_PUT_PEM = 11,
	MENU_ITEM_ACTIVATE = 12,
	MENU_ITEM_DEACTIVATE = 13,
	MENU_ITEM_RETURN_TO_JAIL = 14,
	MENU_ITEM_JAILBREAK = 15,
	MENU_ITEM_BACKUP_ACTIVATION = 16
};


static TIiPhoneNotificationCenter *i_phoneNotificationCenter;


void updateStatus(const char *msg, bool waiting)
{

	if (i_phoneNotificationCenter)
	{
		[i_phoneNotificationCenter postPhoneNotification: [NSString stringWithCString:msg encoding:NSUTF8StringEncoding]];
	}
}

void phoneInteractionNotification(int type, const char *msg)
{
	NSLog(@"LSiPhoneController :: phoneInteractionNotification");
	switch (type)
	{
		case NOTIFY_CONNECTED:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_CONNECTED");
			break;
			
			
		case NOTIFY_DISCONNECTED:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_DISCONNECTED" );
			break;
			
			
		case NOTIFY_INITIALIZATION_FAILED:
		
		
		case NOTIFY_CONNECTION_FAILED:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_CONNECTION_FAILED" );
			break;
			
			
		case NOTIFY_ACTIVATION_SUCCESS:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_ACTIVATION_SUCCESS" );
			break;
			
			
		case NOTIFY_DEACTIVATION_SUCCESS:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_DEACTIVATION_SUCCESS" );
			break;
			
			
		case NOTIFY_JAILBREAK_SUCCESS:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_JAILBREAK_SUCCESS" );
			break;
			
			
		case NOTIFY_ACTIVATION_FAILED:
		
		
		case NOTIFY_DEACTIVATION_FAILED:
		
		
		case NOTIFY_PUTPEM_FAILED:
		
		
		case NOTIFY_PUTSERVICES_FAILED:
		
		
		case NOTIFY_PUTFSTAB_FAILED:
		
		
		case NOTIFY_JAILBREAK_FAILED:
		
		
		case NOTIFY_JAILBREAK_FAIL_USER_COULDNT_HOLD:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_JAILBREAK_FAIL_USER_COULDNT_HOLD" );
			
			
		case NOTIFY_GET_ACTIVATION_FAILED:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_GET_ACTIVATION_FAILED" );
			break;
			
			
		case NOTIFY_PUTPEM_SUCCESS:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_PUTPEM_SUCCESS" );
			
			
		case NOTIFY_GET_ACTIVATION_SUCCESS:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_GET_ACTIVATION_SUCCESS" );
			break;
			
			
		case NOTIFY_JAILBREAK_RECOVERY_WAIT:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_JAILBREAK_RECOVERY_WAIT" );
			break;
			
			
		case NOTIFY_JAILBREAK_RECOVERY_CONNECTED:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_JAILBREAK_RECOVERY_CONNECTED" );
			break;
			
			
		case NOTIFY_JAILBREAK_RECOVERY_DISCONNECTED:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_JAILBREAK_RECOVERY_DISCONNECTED" );
			break;
			
			
		case NOTIFY_JAILBREAK_RESTORE_CONNECTED:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_JAILBREAK_RESTORE_CONNECTED" );
			break;
			
			
		case NOTIFY_JAILBREAK_RESTORE_DISCONNECTED:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_JAILBREAK_RESTORE_DISCONNECTED" );
			break;
			
			
		case NOTIFY_JAILBREAK_CANCEL:
			NSLog(@"LSiPhoneController :: phoneInteractionNotification :: NOTIFY_JAILBREAK_CANCEL" );
			break;
			
		case NOTIFY_CONNECTION_SUCCESS:
		
		case NOTIFY_INITIALIZATION_SUCCESS:
		
		case NOTIFY_PUTFSTAB_SUCCESS:
		
		case NOTIFY_PUTSERVICES_SUCCESS:
		
		default:
			break;
	}

}

void utilityFunctionNotification(int type, const char *msg)
{
//	if (g_mainWindow) {

		switch (type) {
			case NOTIFY_ACTIVATION_GEN_FAILED:
//				[g_mainWindow displayAlert:@"Failure" message:[NSString stringWithCString:msg encoding:NSUTF8StringEncoding]];
				break;
			case NOTIFY_ACTIVATION_GEN_SUCCESS:
			default:
				break;
		}

//	}
}


@implementation TIiPhoneNotificationCenter


- (id)init
{
	if (self = [super init])
	{
		m_connected = false;
		m_recoveryMode = false;
		m_restoreMode = false;
		m_jailbroken = false;
		m_activated = false;
		m_statusSpinning = false;
		m_performingJailbreak = false;
		m_returningToJail = false;
		i_phoneInteraction = NULL;
		m_modal = false;
		
		i_phoneInteraction = PhoneInteraction::getInstance(updateStatus, phoneInteractionNotification);
	}
	
	return self;
}

- (void)postPhoneNotification: (NSString *)postMessage
{
	[self postNotificationName: postMessage  object: nil];

}


@end
